#include "graphicsitem.h"

#include <QPixmap>
#include <QDebug>
#include <handler.h>
GraphicsItem::GraphicsItem()
{
    this->setCursor(QCursor(QPixmap(":/curse/images/chui_up.png")));
    this->setPixmap(QPixmap(":/mouse/images/bg_0.png"));
}

void GraphicsItem::setMouse(bool mouse)
{
    this->mouse = mouse;
}

bool GraphicsItem::isMouse()
{
    return this->mouse;
}
void GraphicsItem::setStart(bool start)
{
    this->start = start;
}
bool GraphicsItem::isStart()
{
    return this->start;
}
void GraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    this->setCursor(QCursor(QPixmap(":/curse/images/chui_up.png")));
}
void GraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//    qDebug()<<"点击事件"<<endl;
//    每次打到老鼠就加分
    //鼠标改变
    this->setCursor(QCursor(QPixmap(":/curse/images/chui_down.png")));
    if(this->isStart())
    {
        Handler *handler = Handler::getInstance();
        if(this->isMouse())
        {
            qDebug()<<"加分"<<endl;
           handler->addScore(); //发送信号
           this->setPixmap(QPixmap(":/mouse/images/mouse_dead.png"));

           //防止重复打击
           this->setMouse(false);

        }else
        {
            qDebug()<<"无加分"<<endl;
        }
    }

}
